PHP W3 Validator API, Is this good? [closed]
Posted
by
Josh Purcell
on Pro Webmasters
See other posts from Pro Webmasters
or by Josh Purcell
Published on 2012-10-31T11:10:14Z
Indexed on
2012/10/31
23:17 UTC
Read the original article
Hit count: 276
I was trying to find a way to see if my site's code was valid or not but I continuously going over to W3 Validator so I decided to make an "API" however it really isn't!
I just wanted to know if anybody can find a better solution to the one I have made. This is what I currently use, with the usage of ?uri=http://www.mydomain.com :
<?php
if(!$_GET['uri']) {
echo "No URI!";
}
else {
$CheckURI = "http://validator.w3.org/check?uri=".$_GET['uri'];
$URL = file_get_contents($CheckURI);
$Start = strpos($URL, "<title>") + 7;
$End = strpos($URL, "</title>");
$Title = substr($URL, $Start, $End-$Start);
if(preg_match('[Invalid]',$Title)) {
//Code is INVALID
echo "<a href='$CheckURI' title='This is not good!' target='_BLANK'>INVALID Source</a>";
}
elseif(preg_match('[Valid]',$Title)) {
//Code is VALID
echo "<a href='$CheckURI' title='Check It Yourself!' target='_BLANK'>Valid Source</a>";
}
else {
//It Went WRONG
echo "";
}
}
© Pro Webmasters or respective owner